<template>
  <!-- 我申报的金融产品 -->
  <div class="layout">
    <ContainerTitle text="我的金融诉求"></ContainerTitle>
    <div class="msgDiv">
      <el-table
        :data="myFinanceProductAppeal"
        style="width: 100%"
        min-height="400"
        :border="true"
        :header-cell-style="{ background: '#F4F4F4', color: '#045DB9' }"
      >
        <el-table-column prop="title" label="诉求标题" width="160">
        </el-table-column>
        <el-table-column prop="contacts" label="联系人" width="80">
        </el-table-column>
        <el-table-column prop="contactNumber" label="联系电话" width="120">
        </el-table-column>

        <el-table-column prop="financeType" label="金融类型" width="120">
          <template slot-scope="scope">
            <span>
              {{ $selectDict(appealList, scope.row.financeType).dictLabel }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="publishTime" label="发布时间" width="150">
        </el-table-column>
        <el-table-column label="状态" width="100">
          <template slot-scope="scope">
            <span
              :style="'color: ' + formatApplyStatus(scope.row.state).color"
              >{{ formatApplyStatus(scope.row.state).label }}</span
            >
          </template>
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <span class="rowBtn" @click="gotoDetail(scope.row)">查看</span>
            <span
              class="rowBtn"
              v-if="scope.row.state == 0 || scope.row.state == 3"
              @click="gotoEdit(scope.row)"
              >编辑</span
            >
            <span
              class="rowBtn"
              v-if="scope.row.state == 0"
              @click="open(scope.row.id)"
              >删除</span
            >
            <span
              class="rowBtn"
              v-if="scope.row.state == 0"
              @click="Release(scope.row.id)"
              >发布</span
            >
            <span
              class="rowBtn"
              @click="firm(scope.row.id)"
              v-if="scope.row.state == 2"
              >确认</span
            >
            <span
              class="rowBtn"
              @click="again(scope.row)"
              v-if="scope.row.state == 3"
              >再次申请</span
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[5, 10, 15, 20, 25, 30]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import { getAppealList, appealDel, appealFinished, appealSubmit } from "@/common/api/company.js";
export default {
  data() {
    return {
      name: "finance",
      currentPage: 1,
      pageSize: 10,
      total: 0,
      crumbs: [
        {
          label: "企业空间",
          value: "company",
          // choose: true,
        },
        {
          label: "金融服务",
          value: "finance",
        },
        {
          label: "我的金融诉求",
          value: "myFinanceProductAppeal",
          choose: true,
        },
      ],
      myFinanceProductAppeal: [],
      applyStatusList: [
        { value: 0, label: "待发布", color: "#333333" },
        { value: 1, label: "待审核", color: "#333333" },
        { value: 2, label: "审核通过", color: "#10A217" },
        { value: 3, label: "审核未通过", color: "#d00000" },
        { value: 9, label: "已完成", color: "#333333" },
      ],
      status: [],
      appealList: [],
    };
  },
  mounted() {
    this.getDict();
    this.getList();
  },

  methods: {
    async getList() {
      let res = await getAppealList({ pageNum: this.currentPage, pageSize: this.pageSize });
      if (res.code == 200) {
        this.myFinanceProductAppeal = res.rows;
        this.total = res.total;
        console.log(res.rows);
      }
    },
    // 字典
    async getDict() {
      // 调用公共方法中的查询字典表
      this.getDictList(this,`finance_appeal_type`).then(res => {
        this.appealList = res.finance_appeal_type;
      })
    },

    formatApplyStatus: function (financingStatusVal) {
      let ns = this;
      for (let i = 0; i < ns.applyStatusList.length; i++) {
        if (financingStatusVal == ns.applyStatusList[i].value) {
          return ns.applyStatusList[i];
        }
      }
      return { label: "" };
    },

    async Del(ids) {
      let res = await appealDel(ids);
      if (res.code == 200) {
        this.getList();
      }
    },
    // 确认
    async confirm(ids) {
      let res = await appealFinished({ id: ids });
      if (res.code == 200) {
        this.getList();
      }
    },
    // 确认弹框
    firm(id) {
      this.$confirm("是否确认?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.confirm(id);
          this.getList();
          this.$message({
            type: "success",
            message: "确认成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消确认",
          });
        });
    },
    // 删除弹框
    open(id) {
      console.log(id);
      this.$confirm("此操作将永久删除该内容, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.Del(id);
          this.getList();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 发布弹框
    Release(id) {
      this.$confirm("此操作将发布该内容, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.getRelease(id);
          this.getList();
          this.$message({
            type: "success",
            message: "发布成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消发布",
          });
        });
    },
    // 发布
    async getRelease(ids) {
      let res = await appealSubmit({ id: ids });
      console.log(ids);
      if (res.code == 200) {
        console.log(this.id);
        this.getList();
      }
    },

    // 再次申请弹框
    again(id) {
      console.log(id);
      this.$confirm("是否再次申请?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.gotoEdit(id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 查看详情
    gotoDetail(row) {
      this.$router.push({
        name: "myFinanceProductAppealDetail",
        query: { id: row.id, statusType: this.statusType },
      });
    },
    // 去编辑
    gotoEdit(row) {
      this.$router.push({
        name: "myFinanceProductAppealEdit",
        query: { id: row.id },
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList();
    },
  },
};
</script>
<style scoped>
.breadcrumb {
  width: 1000px;
  margin: 20px 0;
}

.roomDiv {
  display: flex;
  justify-content: center;
}

.roomDiv .leftDiv {
  width: 200px;
  text-align: left;
}

.roomDiv .rightDiv {
  width: 800px;
  margin-left: 30px;
}
.titleDiv {
  border-bottom: 2px solid #045db9;
  text-align: left;
  padding: 10px;
  font-size: 20px;
  font-weight: bold;
  color: #045db9;
  margin-bottom: 20px;
}
.layout {
  min-height: 100vh;
  position: relative;
  padding-bottom: 150px;
  box-sizing: border-box;
}
.msgDiv {
  margin: 40px 0;
}

.block {
  margin-top: 14px;
  text-align: right;
}
.rowBtn {
  margin-right: 12px;
  cursor: pointer;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}
</style>